package com.xwj.exception.solution_1.demo.service;

import com.xwj.exception.solution_1.demo.entity.User;
import com.xwj.exception.solution_1.demo.enums.BusinessResponseEnum;
import com.xwj.exception.common.exceptions.BusinessException;
import org.springframework.stereotype.Service;

/**
 * @Author: xiaowajiang
 * @Date: 2022-04-05 11:31
 * @Description:
 **/
@Service
public class UserService {

    /**
     * 模拟获取员工
     * 根据参数不同，模拟不同情况下的异常
     * @param id
     * @return
     */
    public User selectById(Integer id) {
        switch (id) {
            case 1:
                return null;
            case 2:
                return new User("xiaowajiang");
            case 3:
                int i = 0 / 0;
                return new User("xiaowajiang");
            case 4:
                User user = null;
                user.toString();
                return user;
            default :
                BusinessResponseEnum responseEnum = BusinessResponseEnum.USER_NOT_FOUND;
                throw new BusinessException(responseEnum.getCode(), responseEnum.getMessage());
        }
    }
}
